package com.codeplex.tdmg4mc;

import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentText;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;

public class TDMGKeyInput
{
	public static boolean left=false;
	public static boolean right=false;
	public static boolean shoot=false;
	public static boolean remove=false;
	public static boolean boost=false;
	public static boolean auto=false;
	public static boolean autoToggle=true;
	public static Key leftKey=new Key(Keyboard.KEY_A);
	public static Key rightKey=new Key(Keyboard.KEY_D);
	public static Key shootKey=new Key(Keyboard.KEY_W);
	public static Key removeKey=new Key(Keyboard.KEY_S);
	public static Key boostKey=new Key(Keyboard.KEY_SPACE);
	public static Key autoKey=new Key(Keyboard.KEY_Z);
	public static boolean leftPress=false;
	public static boolean rightPress=false;
	private static boolean shootPress=false;
	private static boolean removePress=false;
	private static boolean autoPress=false;

	public static void update()
	{
		boolean shift=Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)||Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
		boolean ctrl=Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)||Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
		boolean alt=Keyboard.isKeyDown(Keyboard.KEY_LMENU)||Keyboard.isKeyDown(Keyboard.KEY_RMENU);
		if(leftKey.modifierEqual(shift, ctrl, alt)&&Keyboard.isKeyDown(leftKey.getKey()))
		{
			if(!leftPress) leftPress=left=true;
		}
		else leftPress=false;
		if(rightKey.modifierEqual(shift, ctrl, alt)&&Keyboard.isKeyDown(rightKey.getKey()))
		{
			if(!rightPress) rightPress=right=true;
		}
		else rightPress=false;
		if(shootKey.modifierEqual(shift, ctrl, alt)&&Keyboard.isKeyDown(shootKey.getKey()))
		{
			if(!shootPress) shootPress=shoot=true;
		}
		else shootPress=false;
		if(removeKey.modifierEqual(shift, ctrl, alt)&&Keyboard.isKeyDown(removeKey.getKey()))
		{
			if(!removePress) removePress=remove=true;
		}
		else removePress=false;
		if(boostKey.modifierEqual(shift, ctrl, alt)&&Keyboard.isKeyDown(boostKey.getKey())) boost=true;
		if(autoKey.modifierEqual(shift, ctrl, alt)&&Keyboard.isKeyDown(autoKey.getKey()))
		{
			if(!autoPress)
			{
				if(autoToggle)
				{
					autoPress=true;
					auto=!auto;
					Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(String.format("[TDMG]Auto mode is %s.",auto?"enabled":"disabled")));
				}
				else autoPress=auto=true;
			}
		}
		else if(autoToggle) autoPress=false;
		else autoPress=auto=false;
	}
}
